#include "Object3D.h"
#include "Angles/MathAngles.h"

#if defined (_DEBUG)
#include "Memory/MemLeaks.h"
#endif

//-------------------------------------------------
CObject3D::CObject3D(const Vect3f& _position, const Vect3f& _scale, float _fYaw, float _fPitch, float _fRoll /* = 0.f */)
	: m_Position(_position)
	, m_Scale(_scale)
	, m_fYaw(_fYaw)
	, m_fPitch(_fPitch)
	, m_fRoll(_fRoll)
	, m_bVisible(true)
{

}

//-------------------------------------------------
CObject3D::CObject3D()
	: m_Position(v3fZERO)
	, m_Scale(v3fUNIT)
	, m_fYaw(0.f)
	, m_fPitch(0.f)
	, m_fRoll(0.f)
	, m_bVisible(true)
{

}

//-------------------------------------------------
CObject3D::~CObject3D()
{

}

//-------------------------------------------------
const Mat44f CObject3D::GetRotationMatrix() const
{
	Mat44f rotationY	= m44fIDENTITY;
	Mat44f rotationX	= m44fIDENTITY;
	Mat44f rotationZ	= m44fIDENTITY;

	rotationX.SetFromAngleX	(Math::Angles::Deg2Rad<float>(m_fPitch));
	rotationY.SetFromAngleY	(Math::Angles::Deg2Rad<float>(m_fYaw));
	rotationZ.SetFromAngleZ	(Math::Angles::Deg2Rad<float>(m_fRoll));

	Mat44f rotMatrix = (rotationY * rotationX * rotationZ);

	return rotMatrix;
}

//-------------------------------------------------
const Mat44f CObject3D::GetTransform() const
{
	Mat44f world		= m44fIDENTITY;
	Mat44f scale		= m44fIDENTITY;
	Mat44f rotationY	= m44fIDENTITY;
	Mat44f rotationX	= m44fIDENTITY;
	Mat44f rotationZ	= m44fIDENTITY;
	Mat44f translation	= m44fIDENTITY;

	translation.SetFromPos	(m_Position);
	scale.SetFromScale		(m_Scale.x, m_Scale.y, m_Scale.z);
	rotationX.SetFromAngleX	(Math::Angles::Deg2Rad<float>(m_fPitch));
	rotationY.SetFromAngleY	(Math::Angles::Deg2Rad<float>(m_fYaw));
	rotationZ.SetFromAngleZ	(Math::Angles::Deg2Rad<float>(m_fRoll));

	world = translation * scale * (rotationY * rotationX * rotationZ);

	return world;
}